<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class Base extends Controller
{
    public function __construct(){
        parent::__construct();

        $login_user = session("cch_user");
        if (empty($login_user)) {
            $cch_user_id = cookie('cch_user_id');
            if ( $cch_user_id > 0 ) {
                $login_user = Db::name('user')->where('id',$cch_user_id)->find();
                if (!empty($login_user)) {
                    session('cch_user',$login_user);
                }
            }
        }
        $action = strtolower(request()->action());
        $exception = array_map('strtolower',$this->exception);
        if(empty($login_user) && !in_array($action, $exception)){
            session('login_redirect_url',$_SERVER['REQUEST_URI']);
            $this->redirect(url('user/login'));
        }
        $this->login_user = $login_user;

        $tmp_configs = Db::name('config')->select();
        $configs = [];
        foreach ($tmp_configs as $k => $vo) {
            $configs[$vo['key']] = $vo['value'];
        }


        // $login_user = Db::name('user')->where('id',1)->find();
        // $this->login_user = $login_user;
        $this->page_info = [
            'action'=>$action,
            'controller'=>strtolower(request()->controller()),
            'path'=>request()->path()
        ];
        $this->page_info['controller'] = explode('/', $this->page_info['path'])[1];
        $this->assign([
            'login_user'=>$login_user,
            'configs'=>$configs
        ]);
    }




}
